package com.seckill.dao;

import com.seckill.domain.MiaoshaOrder;
import com.seckill.domain.OrderInfo;
import org.apache.ibatis.annotations.*;

/**
 * @author yangjunwei
 * @date 2021/11/1 4:19 下午
 */
@Mapper
public interface OrderInfoDao {

    @Select("select * from miaosha_order where goods_id = #{goodsId} and user_id=#{userId} ")
    MiaoshaOrder selectMiaoshaOrderBy(@Param("goodsId") long goodsId, @Param("userId") long userId);

    /**
     * 插入订单信息-主键返回
     */
    @Insert(" INSERT INTO order_info (`user_id`, `goods_id`, `delivery_addr_id`, `goods_name`, `goods_count`, `goods_price`, `order_channel`, `status`, `create_date`, `pay_date`) " +
            "VALUES (#{userId}, #{goodsId}, #{deliveryAddrId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel}, #{status}, #{createDate}, #{payDate});")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = long.class, before = false, statement = "select last_insert_id()")
    long insertOrderInfo(OrderInfo orderInfo);

    @Select("select * from order_info where id = #{orderId}")
    OrderInfo getOrderById(@Param("orderId") Integer orderId);

    @Update("update order_info set status = #{status} where id=#{orderId}")
    void updateOrderStatusByOrderId(@Param("orderId") Integer orderId, @Param("status") Integer status);

}
